www.gusucode.com > 基于马尔科夫随机场的图像分割matlab源码。包括ICM迭代条件模式求解最大后验概率算法 > code23/matlab MRF toy examples/showIm.m
function imRet = showIm(im, varargin); % function showIm (im, varargin); % % An image "im" may be a bare image: ie, a [HxWxN] array % or a cell array containing, in order, % { the bare image, % an *optional* range for this image, [min,max] % an *optional* title string for this image % an *optional* xlabel string for this image % } % if no range is provided, the image is shown using the range % passed in above, in the varargin array. If that wasn't provided % either, the image is scaled so min is 0 and max is 1. % if no title string is provided, the title is blank % if no xlabel is provided, the xlabel displays the range and dimensions % of the image, unless "text_flag", passed in the varargin array, above, % is 0, in which case the xlabel is blank. % % Additionally, im may be a cell array, with each element being of the % structure above. In this case, showIm calls "subplot" before rendering % each image. % [range, filter, text_flag] = utParseArgs(varargin,{ { 'range', [] }, { 'filter', [] }, { 'text_flag', 1 } }); if (~iscell(im)) im = { im }; elseif ((size(im,1)==1) & (size(im,2)>1) & (size(im,2)<5)) isICand = 1; t=2; if (isICand & length(im)>=t) if (~isstr(im{t})) c = im{t}; t=t+1; if ~(isnumeric(c) & (length(size(c))==2) & (size(c,1)==1) & (size(c,2)==2)) isICand=0; end; end; end; if (isICand & length(im)>=t) if (~isstr(im{t})) isICand=0; else t=t+1; end; end; if (isICand & length(im)>=t) if (~isstr(im{t})) isICand=0; else t=t+1; end; end; if (isICand) im = { im }; end; end; imRet = cell(size(im)); %------------------------------------------------------------ n = prod(size(im)); plotLoc = reshape(1:n,size(im,2),size(im,1))'; for i = 1:n lrange = range; cel = im{i}; if (~isempty(cel)) if (n>1) subplot(size(im,1),size(im,2),plotLoc(i)); end; title_str = []; xlabel_str = []; if (~iscell(cel)) img = cel; else img = cel{1}; t=2; if (length(cel)>=t) if (~isstr(cel{t})) lrange = cel{t}; t=t+1; end; end; if (length(cel)>=t) if (isstr(cel{t})) title_str = cel{t}; t=t+1; end; end; if (length(cel)>=t) if (isstr(cel{t})) xlabel_str = cel{t}; t=t+1; end; end; end; if (~isempty(filter)) img = filter(img); end; if (~isempty(lrange)) mn = lrange(1); mx = lrange(2); else mn = min(min(min(img))); mx = max(max(max(img))); end; if ((mx-mn) <= eps) mn = mn - 0.5; mx = mx + 0.5; end; img(img<mn) = mn; img(img>mx) = mx; img = (img-mn)/(mx-mn); if (size(img,3)==1) img = repmat(img,[1 1 3]); elseif (size(img,3)==2) img(:,:,3) = img(:,:,2); elseif (size(img,3)>3) img = img(:,:,1:3); end; imRet{i} = img; image(img); axis('off'); axis('image'); % colormap []; if (~isempty(title_str)) title(title_str); end; if (text_flag | ~isempty(xlabel_str)) if (isempty(xlabel_str)) xlabel_str = sprintf('%s Range [%.3g, %.3g] \n Dims [%d, %d] ', ... utIf(n>1,sprintf('#%d:',plotLoc(i)),''), ... mn, mx, size(img,1), size(img,2)); end; xlabel(xlabel_str); h = get(gca,'Xlabel'); set(h,'FontSize', 11); orig_units = get(h,'Units'); set(h,'Units','points'); pos = get(h,'Position'); pos(1:2) = pos(1:2) + [0, 14]; set(h,'Position',pos); set(h,'Units',orig_units); set(h,'Visible','on'); end; end; end;